package com.origin.netlibrary.greendao;

import android.content.Context;
import android.util.Log;


import com.github.yuweiguocn.library.greendao.MigrationHelper;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.database.Database;

/**
 * 替换成自己的升级控件
 */
public class GreenDaoOpenHelper extends DaoMaster.DevOpenHelper {
    Class<? extends AbstractDao<?, ?>>[] mDaoClasses;


    public GreenDaoOpenHelper(Context context, String name, Class<? extends AbstractDao<?, ?>>[] daoClasses) {
        super(context, name);
        mDaoClasses = daoClasses;
    }

    @Override
    public void onUpgrade(Database db, int oldVersion, int newVersion) {
        Log.i("version", "$oldVersion---先前和更新之后的版本---$newVersion");
        MigrationHelper.migrate(db, new MigrationHelper.ReCreateAllTableListener() {

            @Override
            public void onCreateAllTables(Database db, boolean ifNotExists) {
                DaoMaster.createAllTables(db, ifNotExists);
            }

            @Override
            public void onDropAllTables(Database db, boolean ifExists) {
                DaoMaster.dropAllTables(db, ifExists);
            }
        }, mDaoClasses);
    }
}
